<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
namespace core;
defined('BY_JYA') or exit('error');
class develop{
	public function appreplace($path,$type=''){
		$files=cfc('files')->file_tree($path);
		foreach($files as $file){
			if(is_file($path.$file)){
				$data=file_get_contents($path.$file);
				if(strpos($file,'_wxauth.wxml')!== false){
					if($type=='aliapp'){
						$data=str_replace('bindgetuserinfo=','onGetAuthorize=',$data);
						$data=str_replace('open-type="getUserInfo"','open-type="getAuthorize" onError="closeAuthM" scope="userInfo"',$data);
						$data=str_replace('bindtap="info_login"','open-type="getAuthorize" scope="userInfo" onGetAuthorize="info_login"',$data);
					}else{
						$data=str_replace('bindgetuserinfo=','bindtap=',$data);
					}
				}
				$pathinfo=pathinfo($path.$file);
				if($pathinfo['extension']=='wxml'){
					$data=$this->apphtml($data,$type);
					$newfile=str_replace('wxml','',$path.$file);
					if($type=='ttapp'){
						//抖音又不支持wxml
						unlink($path.$file);
						file_put_contents($newfile.'ttml',$data);
					}elseif($type=='aliapp'){
						unlink($path.$file);
						if(strpos($file,'_navigation-bar.wxml')!== false){
							file_put_contents($newfile.'axml','<!--no-->');
						}elseif(strpos($file,'/pages/_menu.wxml')!== false){
							file_put_contents($newfile.'axml','<include src="/pages/_menu_ali.axml"/>');
						}else{
							file_put_contents($newfile.'axml',$data);
						}
					}elseif($type=='baiduapp'){
						unlink($path.$file);
						file_put_contents($newfile.'swan',$data);
					}
					
				}elseif($pathinfo['extension']=='wxss'){
					if((strpos($file,'/app.wxss')!== false) && $type=='aliapp'){
						$data=str_replace("image{width:100%;height:100%;}"," ",$data);
						$data=str_replace("--topbarheight:150rpx","--topbarheight:0",$data);
					}
					$data=$this->appcss($data,$type);
					
					$newfile=str_replace('wxss','',$path.$file);
					if($type=='ttapp'){
						//抖音又不支持wxss
						unlink($path.$file);
						file_put_contents($newfile.'ttss',$data);
					}elseif($type=='aliapp'){
						unlink($path.$file);
						file_put_contents($newfile.'acss',$data);
					}elseif($type=='baiduapp'){
						unlink($path.$file);
						file_put_contents($newfile.'css',$data);
					}
				}elseif($pathinfo['extension']=='js'){
					if((strpos($file,'/app.js')!== false) && $type=='aliapp'){
						$data=str_replace("('resource/js","('/resource/js",$data);
					}
					if((strpos($file,'/app.js')!== false) && $type=='baiduapp'){
						$data=str_replace("('resource/js","('./resource/js",$data);
						$data=str_replace("('/resource/js","('./resource/js",$data);
					}
					if((strpos($file,'/util.js')!== false) && $type=='aliapp'){
						$data=str_replace('res.code','res.authCode',$data);
						$data=str_replace("('base64.js","('/resource/js/base64.js",$data);
						$data=str_replace("('jinyun_socket.js","('/resource/js/jinyun_socket.js",$data);
						$data=str_replace("('md5.js","('/resource/js/md5.js",$data);
					}
					if((strpos($file,'/util.js')!== false) && $type=='baiduapp'){
						$data=str_replace("('base64.js","('./base64.js",$data);
						$data=str_replace("('jinyun_socket.js","('./jinyun_socket.js",$data);
						$data=str_replace("('md5.js","('./md5.js",$data);
						$data=str_replace("wx.login","swan.getLoginCode",$data);
					}
					if((strpos($file,'/tabbar/tabbar.js')!== false) && $type=='aliapp'){
						$data=str_replace("attached: function attached()","didMount ()",$data);
						$data=str_replace("this.triggerEvent","//this.triggerEvent",$data);
					}
					$data=$this->appjs($data,$type);
					file_put_contents($path.$file,$data);
				}elseif($type!='wxapp' && (strpos($file,'components/')=== false) && $pathinfo['extension']=='json' && $file!='/app.json' && $file!='/project.config.json' && $file!='/project.swan.json' && $file!='/sitemap.json'){
					$data='
{
		"usingComponents": {
				"mp-badge": "/components/badge/badge",
				"base-modal" : "/components/base-modal/index",
				"jy-modal": "/components/jy-modal/index",
				"mp-navigation-bar": "/components/navigation-bar/navigation-bar",
				"mp-tabbar": "/components/tabbar/tabbar"
		}
}';
					file_put_contents($path.$file,$data);
				}
			}
		}
				
		return true;
	}
	public function apphtml($html,$type=''){
		if($type=='ttapp'){
			//抖音已支持wx
			$html=str_replace('wx:if','tt:if',$html);
			$html=str_replace('wx:elif','tt:elif',$html);
			$html=str_replace('wx:else','tt:else',$html);
			$html=str_replace('wx:for','tt:for',$html);
			$html=str_replace('wx:for-index','tt:for-index',$html);
			$html=str_replace('wx:for-item','tt:for-item',$html);
			$html=str_replace('wx:key','tt:key',$html);
			$html=str_replace('.wxml','.ttml',$html);
			$html=str_replace('<i ','<text ',$html);
			$html=str_replace('<i>','<text>',$html);
			$html=str_replace('</i>','</text>',$html);
			$html=str_replace('<span>','<text>',$html);
			$html=str_replace('<span ','<text ',$html);
			$html=str_replace('</span>','</text>',$html);
			$html=str_replace('<a ','<text ',$html);
			$html=str_replace('<a>','<text>',$html);
			$html=str_replace('</a>','</text>',$html);
			$html=str_replace('<p ','<text ',$html);
			$html=str_replace('<p>','<text>',$html);
			$html=str_replace('</p>','</text>',$html);
		}elseif($type=='aliapp'){
			$html=str_replace('wx:if','a:if',$html);
			$html=str_replace('wx:elif','a:elif',$html);
			$html=str_replace('wx:else','a:else',$html);
			$html=str_replace('wx:for','a:for',$html);
			$html=str_replace('wx:for-index','a:for-index',$html);
			$html=str_replace('wx:for-item','a:for-item',$html);
			$html=str_replace('wx:key','a:key',$html);
			$html=str_replace('bindtap=','onTap=',$html);
			$html=str_replace('.wxml','.axml',$html);
			$html=str_replace('<i ','<text ',$html);
			$html=str_replace('<i>','<text>',$html);
			$html=str_replace('</i>','</text>',$html);
			$html=str_replace('<span>','<text>',$html);
			$html=str_replace('<span ','<text ',$html);
			$html=str_replace('</span>','</text>',$html);
			$html=str_replace('<a ','<text ',$html);
			$html=str_replace('<a>','<text>',$html);
			$html=str_replace('</a>','</text>',$html);
			$html=str_replace('<p ','<text ',$html);
			$html=str_replace('<p>','<text>',$html);
			$html=str_replace('</p>','</text>',$html);
			$html=str_replace('<include src="/pages/_menu.wxml"/>','<mp-tabbar iconimg="{{false}}" list="{{pluginnav}}"></mp-tabbar>',$html);
			$html=str_replace('bindchange=','onChange=',$html);
			$html=str_replace('bindreset=','onReset=',$html);
			$html=str_replace('bindsubmit=','onSubmit=',$html);
			$html=str_replace('bindinput=','onInput=',$html);
		}elseif($type=='baiduapp'){
			$html=str_replace('wx:if','s-if',$html);
			$html=str_replace('wx:elif','s-elif',$html);
			$html=str_replace('wx:else','s-else',$html);
			$html=str_replace('wx:for','s-for',$html);
			$html=str_replace('wx:for-index','s-for-index',$html);
			$html=str_replace('wx:for-item','s-for-item',$html);
			$html=str_replace('wx:key','s-key',$html);
			$html=str_replace('.wxml','.swan',$html);
		}		
		return $html;
	}
	public function appjs($jsdata,$type=''){
		$key_str='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
		if($type=='ttapp'){
			$jsdata=str_replace('wx.showNavigationBarLoading','//wx.showNavigationBarLoading',$jsdata);
			$jsdata=str_replace('wx.hideNavigationBarLoading','//wx.hideNavigationBarLoading',$jsdata);
			$jsdata=str_replace('wx.getMenuButtonBoundingClientRect','wx.getMenuButtonLayout',$jsdata);
			$jsdata=str_replace('wx.','tt.',$jsdata);
			//一些误替换，恢复
			for($i=0;$i<strlen($key_str);$i++){//遍历字符串恢复
				$jsdata=str_replace($key_str[$i].'tt.',$key_str[$i].'wx.',$jsdata);
			}
		}elseif($type=='aliapp'){
			$jsdata=str_replace('wx.','my.',$jsdata);
			$jsdata=str_replace('my.showNavigationBarTitle','my.showNavigationBarLoading',$jsdata);
			$jsdata=str_replace('my.setNavigationBarTitle','my.setNavigationBar',$jsdata);
			$jsdata=str_replace('app.fansinfo','//app.fansinfo',$jsdata);
			$jsdata=str_replace('my.login','my.getAuthCode',$jsdata);
			$jsdata=str_replace('my.showModal','my.confirm',$jsdata);
			//一些误替换，恢复
			for($i=0;$i<strlen($key_str);$i++){//遍历字符串恢复
				$jsdata=str_replace($key_str[$i].'my.',$key_str[$i].'wx.',$jsdata);
			}
		}elseif($type=='baiduapp'){
			$jsdata=str_replace('wx.','swan.',$jsdata);
			//一些误替换，恢复
			for($i=0;$i<strlen($key_str);$i++){//遍历字符串恢复
				$jsdata=str_replace($key_str[$i].'swan.',$key_str[$i].'wx.',$jsdata);
			}
		}
		
		return $jsdata;
	}
	public function appcss($css,$type=''){
		if($type=='ttapp'){
			//抖音已支持wxss
			$css=str_replace('.wxss','.ttss',$css);
		}elseif($type=='aliapp'){
			$css=str_replace('.wxss','.acss',$css);
		}elseif($type=='baiduapp'){
			$css=str_replace('.wxss','.css',$css);
		}		
		return $css;
	}
	//H5开始
	public function h5replace($path,$type=''){
		$files=cfc('files')->file_tree($path);
		foreach($files as $file){
			if(is_file($path.$file)){
				$data=file_get_contents($path.$file);
				$pathinfo=pathinfo($path.$file);
				if($pathinfo['extension']=='html'){
					$data=$this->h5html($data,$type);
					$newfile=str_replace('html','',$path.$file);
					unlink($path.$file);
					file_put_contents($newfile.'wxml',$data);	
				}elseif($pathinfo['extension']=='css'){
					$data=$this->h5css($data,$type);
					$newfile=str_replace('css','',$path.$file);
					unlink($path.$file);
					file_put_contents($newfile.'wxss',$data);
				}
			}
		}				
		return true;
	}
	public function h5html($html,$type=''){
		$html=str_replace('.html','.wxml',$html);	
		$html=str_replace('<div','<view',$html);	
		$html=str_replace('</div','</view',$html);	
		$html=str_replace('.css','.wxss',$html);
		$html=str_replace('<div ng-include="','<include src="',$html);
		$html=str_replace('ng-if','wx:if',$html);
		$html=str_replace('ng-repeat','wx:for',$html);
		return $html;
	}
	public function h5css($css,$type=''){
		$css=str_replace('.css','.wxss',$css);	
		return $css;
	}
	//插件生成小程序
	public function pluginapp($name,$wxapp_id,$index_page=''){
		$index_page=$index_page?:$name.'/index/';
		$dir=ROOT_PLUGIN.$name;
		if(!is_dir($dir)){
			exit('插件不存在！');
		}
		$temp_dir=ROOT_AT.'temp/'.random(30);mkdir($temp_dir);		
		//第一步，将小程序包拷贝入临时文件夹
		cfc('files')->file_copy(ROOT_D.'/core/resource/wxapp/wxapp_template',$temp_dir);
		
		//第二步，遍历插件目录，生成页面文件
		$actions=cfc('files')->file_tree($dir.'/custom/actions',array(),'.php');
		$pages=array();
		foreach($actions as $action_file){
			$action=substr($action_file,1,-4);
			if($action=='init'){
				continue;
			}
			$pages[]="\t\t\"{$name}/{$action}/index\",";
			$page_dir=$temp_dir.'/'.$name.'/'.$action;
			cfc('files')->mkdirs($page_dir);
			cfc('files')->file_copy(ROOT_D.'/core/resource/wxapp/page_template',$page_dir);
			$page_html_file=$dir.'/custom/templates/mobile/'.$action.'.html';
			if(is_file($page_html_file)){
				$bar='<include src="/pages/_navigation-bar.wxml"/>';
				$page_data=file_get_contents($page_html_file);
				$page_data=$bar.$page_data;
				//替换<div </div
				$page_data=str_replace('<div','<view',$page_data);
				$page_data=str_replace('</div','</view',$page_data);
				//赋值action
				$pagejs_data=file_get_contents($page_dir.'/index.js');
				$pagejs_data=str_replace('{action}',$action,$pagejs_data);
				file_put_contents($page_dir.'/index.js',$pagejs_data);
				file_put_contents($page_dir.'/index.wxml',$page_data);
			}
		}
		$pages=implode("\n",$pages);
		$window=ijson_encode(array('navigationStyle'=>'custom'));
		$app_json=file_get_contents($temp_dir.'/app.json');
		$app_json=str_replace('{pages}',$pages,$app_json);
		$app_json=str_replace('{window}',$window,$app_json);
		file_put_contents($temp_dir.'/app.json',$app_json);
		$wxapp=pdo_get('core_account_wxapp',array('id'=>$wxapp_id));
		//全局样式
		$wxapp['syscolor']=$wxapp['syscolor']?:'#18bc9c';
		$css_json=file_get_contents($temp_dir.'/app.wxss');
		$css_json=str_replace('{syscolor}',$wxapp['syscolor'],$css_json);
		file_put_contents($temp_dir.'/app.wxss',$css_json);
		$setting=array(
			'index_url'=>SITEROOT."custom/index.php?i={$_SESSION['uniacid']}&wxgid={$wxapp_id}",
			'api_url'=>SITEROOT."api.php?this=custom",
			'att_url'=>ATTACHMENT_URL,
			'siteroot'=>SITEROOT,
			'uniacid'=>$_SESSION['uniacid'],
			'wxgid'=>$wxapp_id,
			'title'=>$wxapp['title'],
			'sharetitle'=>$wxapp['title'],
			'sharedesc'=>$wxapp['title'],
		);
		$app_js=file_get_contents($temp_dir.'/app.js');
		$app_js=str_replace(array('{index_page}','{setting}','{plugin_name}'),array($index_page,ijson_encode($setting),$name),$app_js);
		file_put_contents($temp_dir.'/app.js',$app_js);
		do{
			$zip=ROOT_AT.'temp/'.random(10).'.temp';
		}while(is_file($zip));
		return $temp_dir;
	}
	public function add_plugins($postdata,$type=3,$isupsql=false){
			$insert_plugin=array(
				'name'=>$postdata['name'],
				'title'=>$postdata['title'],
				'istakeover'=>$postdata['istakeover'],
				'description'=>$postdata['description'],
				'cloud_price'=>$postdata['price'],
				'type'=>$type,
				'style'=>$postdata['style'],
				'intype'=>$postdata['intype'],
				'is_legao'=>$postdata['is_legao'],
				'image'=>$postdata['image'],
				'hide'=>1,
				'is_my'=>1,
				'is_local'=>1,
				'custom_access_type'=>$postdata['custom_access_type'],
				'manage_access_type'=>$postdata['manage_access_type'],
				'basic'=>$postdata['basic'],
			);
			if($isupsql){
				$insert_plugin['cloud_id']=$postdata['id'];
				unset($insert_plugin['hide']);
				unset($insert_plugin['is_local']);	
			}
			pdo_insert('core_plugins',$insert_plugin);
			$id=pdo_insertid();
			//添加权限数据
			$insert_permission=array(
				'type'=>1,
				'plugin'=>$postdata['name'],
				'title'=>$postdata['title'],
			);
			pdo_insert('core_plugin_permissions',$insert_permission);
			$receive=trim($postdata['receive'],';');
			$receive=explode(';',$receive);
			$insert_receive=array();
			if($receive){
				foreach($receive as $row){
					if($row){
						$insert_receive[]=array('plugin'=>$postdata['name'],'type'=>$row);
					}
				}
			}
			foreach($insert_receive as $row){
				pdo_insert('core_receive',$row);
			}
			if(!$isupsql){
				$this->add_pluginsdemo($postdata['name']);
			}
		return $id;
	}
	public function set_versions($id,$plugin_id,$noupplugin=false){
		if(!$plugin_id){
			exi('请先选择插件！','error');
		}
		$plugin=pdo_get('core_plugins',array('id'=>$plugin_id),array('name','version','price','zipfile','status','type','release'));
		$version=pdo_get('core_plugin_version',array('id'=>$id),array('config','zipfile','price','version','sys_version','description','release','status'));
		pdo_update('core_plugin_version',array('status'=>1),array('id'=>$id));
		if($version['release']<=$plugin['release']){
			return false;
		}
		//审核通过操作
		$update=array('version'=>$version['version'],'price'=>$version['price'],'config'=>$version['config'],'release'=>$version['release']);
		if($version['sys_version']){
			$update['sys_version']=$version['sys_version'];
		}
		if($version['description']){
			$update['v_desc']=$version['description'];
		}
		//将审核版本文件同步到插件目录中，并生成新的模块压缩包
		if(!is_dir(ROOT_AT.'plugin_file/'.$plugin['name'])){
				cfc('files')->mkdirs(ROOT_AT. 'plugin_file/'.$plugin['name']);
		}
		file_put_contents(ROOT_AT. 'plugin_file/'.$plugin['name'].'/version.txt','V-'.$version['version']);
		if($version['zipfile']){
			if(!is_dir(ROOT_AT.'temp')){
				cfc('files')->mkdirs(ROOT_AT. 'temp');
			}
			$temp=ROOT_AT.'temp/'.random(30).'.zip';
			//zip文件直接下载，此处进行判断，后期全部采用zip格式，减轻系统压力
			if(substr($version['zipfile'],-4)=='.zip'){
				$url=tomedia($version['zipfile']);
				copy($url,$temp);
			}else{
				$zipdata=cfc('files')->source_read($version['zipfile']);
				file_put_contents($temp,$zipdata);
			}
			$zip = new \ZipArchive();
			$zip->open($temp);
			$zip->extractTo(ROOT_AT. 'plugin_file/'.$plugin['name']);
			$zip->close();
			@unlink($temp);
			//生成新版插件压缩包
		}
		if(!is_dir(ROOT_AT. 'plugin_zip')){
			cfc('files')->mkdirs(ROOT_AT. 'plugin_zip');
		}
		$update['zipfile']=$plugin['zipfile']?$plugin['zipfile']:random(30);
		cfc('files')->zip(ROOT_AT. 'plugin_file/'.$plugin['name'],ROOT_AT.'plugin_zip/'.$update['zipfile'].'.zip');
		$update['md5']=md5_file(ROOT_AT.'plugin_zip/'.$update['zipfile'].'.zip');
		//更新插件数据
		if($noupplugin){
			unset($update['version']);
			unset($update['release']);
		}
		pdo_update('core_plugins',$update,array('id'=>$plugin_id));
		//清空所有一个月前已经失效的版本附件包：
		$yuetime=$version['release']-30*24*3600;
		$versions=pdo_getall('core_plugin_version',array('pid'=>$plugin_id,'release<='=>$yuetime),array('config','zipfile'));
		foreach($versions as $verv){
			cfc('files')->source_del($verv['config']);
			cfc('files')->source_del($verv['zipfile']);
		}
		return true;
	}
	public function getcloud_files($pluginname){
		if(!$pluginname){
			exi('请先选择插件！','error');
		}
		if(!is_dir(ROOT_AT. 'plugin_file/'.$pluginname)){
			return 'empty';
		}
		$files=cfc('files')->file_tree(ROOT_AT. 'plugin_file/'.$pluginname);
		$return=array();
		foreach($files as $file){
			$return[$file]=md5_file(ROOT_AT. 'plugin_file/'.$pluginname.$file);
		}
		return $return;
	}
	public function add_pluginsdemo($pluginname){
		if(!$pluginname || is_dir(ROOT_PLUGIN.$pluginname)){
			return false;
		}
		$search=array('plugin_name'=>$pluginname);
		//添加目录
		@mkdir(ROOT_PLUGIN.$pluginname);
		@mkdir(ROOT_PLUGIN.$pluginname.'/manage');
		@mkdir(ROOT_PLUGIN.$pluginname.'/manage/actions');
		@mkdir(ROOT_PLUGIN.$pluginname.'/manage/templates');
		@mkdir(ROOT_PLUGIN.$pluginname.'/manage/templates/windows');
		@mkdir(ROOT_PLUGIN.$pluginname.'/custom');
		@mkdir(ROOT_PLUGIN.$pluginname.'/custom/actions');
		@mkdir(ROOT_PLUGIN.$pluginname.'/custom/templates');
		@mkdir(ROOT_PLUGIN.$pluginname.'/custom/templates/mobile');
		@mkdir(ROOT_PLUGIN.$pluginname.'/model');
		@mkdir(ROOT_PLUGIN.$pluginname.'/class');
		//添加文件
		$code=<<<TPL
<?php
/*
	插件初始化
*/
namespace {plugin_name};
defined('BY_JYA') or exit('error');
function init(\$plugin){
	//定义本场景的一些独立,为空表示共用电商客的
	\$plugin->weishop_order_detail='';
	\$plugin->weishop_order_list='';
	\$plugin->syscolor=\$plugin->plugin_setting('basic')['syscolor']?:'';
	\$plugin->plugins=array();
}
TPL;
$code=cfc('tools')->replace($search,$code);
file_put_contents(ROOT_PLUGIN.$pluginname.'/init.php',$code);
//添加文件
$code=<<<TPL
<?php
global \$_RQ,\$_AR;
//判断是否来自场景体,底部菜单不变
if(\$_RQ['plugin_name']){
	\$this->session('plugin_name',\$_RQ['plugin_name']);
}
\$plugin_name=\$this->session('plugin_name')?\$this->session('plugin_name'):'';
if(\$plugin_name){
	\$return['footernav']=\$this->plugin(\$plugin_name)->plugin_setting('basic')['footernav'];
}
\$return['pluginset']=\$this->plugin_setting('basic');
?>
TPL;
$code=cfc('tools')->replace($search,$code);
file_put_contents(ROOT_PLUGIN.$pluginname.'/custom/actions/init.php',$code);
//添加文件
$code=<<<TPL
<?php
/*
	本插件：\$this->model('model')->方法名();
	其他地方调用：model('{plugin_name}/model')->方法名();
*/
namespace {plugin_name};
defined('BY_JYA') or exit('error');
class model extends \plugin{
	
}
?>
TPL;
$code=cfc('tools')->replace($search,$code);
file_put_contents(ROOT_PLUGIN.$pluginname.'/class/model.php',$code);
//添加文件
$code=<<<TPL
<?php
/*
	插件链接选择页面
*/
defined('BY_JYA') or exit('error');
//系统链接获取接口
\$return=array();
\$_RQ['op']=\$_RQ['op']?\$_RQ['op']:'list';
\$tabs=array(
	array('op'=>'system','plugin'=>'core','action'=>'tools.link','title'=>'系统页面链接'),
	array('op'=>'list','title'=>'插件页面'),
);
if(\$_RQ['op']=='list'){
	\$return['list']=array(
		array('title'=>'首页','url'=>'{plugin_name}/index//current_plugin={plugin_name}'),
	);
	\$htmls=array(
		'type'=>'list',
		'tabs'=>\$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'pagelist'=>false,'list'=>array(
			array('name'=>'title','title'=>'标题','type'=>'string'),
			array('name'=>'url','title'=>'H5路径','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal_result','name'=>'url','title'=>'选取'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	\$return['htmls']=\$htmls;
	exi(\$return);
}
?>
TPL;
$code=cfc('tools')->replace($search,$code);
file_put_contents(ROOT_PLUGIN.$pluginname.'/manage/actions/link.php',$code);
//cosen添加文件
//以下根据需要添加初始化数据
//基本设置
$code=<<<TPL
<?php
defined('BY_JYA') or exit('error');
\$_RQ['op']=\$_RQ['op']?\$_RQ['op']:'basic';
\$return=array();
/*******basic*******/
if(\$_RQ['op']=='basic'){
	if(\$_RQ['postdata']){
		\$postdata=get_postdata();
		\$this->plugin_setting('basic',\$postdata);
		exi('设置成功');
	}
	\$footernav =array(
		array('title'=>'首页','icon'=>'icon-shouye','action'=>'{plugin_name}/index/'),
		array('title'=>'我的','icon'=>'icon-wo1','action'=>'{plugin_name}/myhome/'),
	);
	\$return['item']=\$this->plugin_setting('basic');
	\$return['item']['footernav']=\$return['item']['footernav']?\$return['item']['footernav']:\$footernav;
	\$htmls=array(
		'type'=>'edit',
		'desc'=>'参数设置',
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'string','title'=>'网站名称','name'=>'title'),
					array('type'=>'image','title'=>'网站logo','name'=>'logo'),
					array('type'=>'string','title'=>'分享标题','name'=>'share_title'),
					array('type'=>'image','title'=>'分享图片','name'=>'share_image'),
					array('type'=>'string','title'=>'分享描述','name'=>'share_desc'),
				)
			),
			array(
					'title'=>'界面UI配色',
					'list'=>array(
						array('type'=>'color_pool','title'=>'选择配色方案','name'=>'syscolor','help'=>''),
						array('type'=>'colorpicker','title'=>'站点颜色','name'=>'syscolor','help'=>'自定义系统颜色系，默认： #18bc9c'),
						array('type'=>'phone_tpl','name'=>'syscolor'),
					)
			),
			array(
				'title'=>'幻灯片',
					'list'=>array(
						array(
							'type'=>'array',
							'name'=>'hdps',
							'add_tip'=>'添加一个幻灯片',
								'list'=>array(
									array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片'),
									array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
									
								),
								'details'=>array(
									array('type'=>'image','name'=>'picurl','title'=>'幻灯片图片','help'=>''),
									array('type'=>'string','name'=>'url','title'=>'幻灯片链接'),
									
								)
						)
					)
			),
			array(
					'title'=>'欢迎幻灯片',
					'list'=>array(
								array('type'=>'switch','title'=>'开启欢迎页面','name'=>'iswelcome','help'=>'开启后，访问首页会先进入欢迎页面！'),
								array('type'=>'array','title'=>'欢迎幻灯片','name'=>'welcomehdps','add_tip'=>'添加一个欢迎幻灯片',
										'list'=>array(
											array('type'=>'string','name'=>'title','title'=>'标题'),
											array('type'=>'image','name'=>'picurl','title'=>'图片'),
											array('type'=>'string','name'=>'url','title'=>'地址'),
										),
										'details'=>array(
											array('type'=>'string','name'=>'title','title'=>'标题'),
											array('type'=>'string','name'=>'desc','title'=>'描述'),
											array('type'=>'image','name'=>'picurl','title'=>'图片','help'=>'推荐尺寸：750*900'),
											array('type'=>'link','name'=>'url','from'=>'action','title'=>'地址'),
										)
								),
					)
			),
			array(
				'title'=>'板块导航',
					'list'=>array(
									array('type'=>'array','name'=>'bankuai','add_tip'=>'添加一个板块导航',
									'list'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'image','name'=>'img','title'=>'导航图片'),
										array('type'=>'string','name'=>'action','title'=>'导航链接'),							
									),
									'details'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'image','name'=>'img','title'=>'导航图片'),							
										array('type'=>'string','name'=>'action','title'=>'导航链接'),
									)
								),
					)
			),
			array(
				'title'=>'底部导航',
					'list'=>array(
									array('type'=>'array','name'=>'footernav','add_tip'=>'添加一个底部导航',
									'list'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'icon','name'=>'icon','from'=>'jinyunicon','title'=>'导航图标'),
										array('type'=>'string','name'=>'action','title'=>'导航链接'),							
									),
									'details'=>array(
										array('type'=>'string','name'=>'title','title'=>'导航名称'),
										array('type'=>'icon','name'=>'icon','from'=>'jinyunicon','title'=>'导航图标','help'=>'图标，例如：icon-shouye'),							
										array('type'=>'link','name'=>'action','from'=>'action','title'=>'导航链接'),
									)
								),
					)
			),
		),
	);
	\$return['htmls']=\$htmls;
	exi(\$return);
}
/*******basic*******/
/*******op*******/

TPL;
$code=cfc('tools')->replace($search,$code);
file_put_contents(ROOT_PLUGIN.$pluginname.'/manage/actions/setting.php',$code);

// 菜单默认
$code=<<<TPL
<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * \$Id: 2017-12-13 03:39:35 apple $
 插件菜单
*/
defined('BY_JYA') or exit('error');
list(\$basicname)=\$arguments;
// （这里是标准平台插件的二级菜单）非场景体不建议使用三级菜单。
return array(
		array('title'=>'应用概况','child'=>array(
				array('url'=>'{plugin_name}/index/','title'=>'应用概况'),
		)),
		array('title'=>'应用公告','child'=>array(
				array('url'=>'core/account.article_list/','title'=>'公告列表'),
				array('url'=>'core/account.article_fenlei/','title'=>'公告分类'),
		)),
		array('title'=>'基本设置','child'=>array(
				array('url'=>'{plugin_name}/setting/','title'=>'基本设置'),
		)),
		array('title'=>'入口管理','child'=>array(
			array('url'=>'{plugin_name}/basic.module_home/cover/ac=index&type=3','title'=>'首页入口'),
		)),
);

TPL;
$code=cfc('tools')->replace($search,$code);
file_put_contents(ROOT_PLUGIN.$pluginname.'/model/menu.php',$code);

// 插件手机端底部菜单
$code=<<<TPL
<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * \$Id: 2017-12-13 03:39:35 apple $
 插件手机端底部菜单
*/
defined('BY_JYA') or exit('error');
\$menus = \$this->plugin_setting('basic')['footernav'];
return \$menus;

TPL;
$code=cfc('tools')->replace($search,$code);
file_put_contents(ROOT_PLUGIN.$pluginname.'/model/custom_mobile_menu.php',$code);
//插件概览
$code=<<<TPL
<?php
/*
	插件概览
*/
defined('BY_JYA') or exit('error');
\$_RQ['op']=\$_RQ['op']?\$_RQ['op']:'get';
\$plugin_name = \$_RQ['basicname'] ? \$_RQ['basicname'] : '';
if(\$_RQ['op']=='get'){
	//显示统计数据
		\$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		\$mounthtime =  mktime(0,0,0,date('m'),1,date('Y'));
		\$access=array();
		\$access['wechat_day']=pdo_count('core_access_log',array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin'],'os'=>2,'createtime >'=>\$daytime));
		\$access['wxapp_day']=pdo_count('core_access_log',array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin'],'os'=>1,'createtime >'=>\$daytime));
		\$access['mobile_day']=pdo_count('core_access_log',array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin'],'os'=>3,'createtime >'=>\$daytime));
		\$access['pc_day']=pdo_count('core_access_log',array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin'],'os'=>4,'createtime >'=>\$daytime));
		\$access['app_day']=pdo_count('core_access_log',array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin'],'os'=>5,'createtime >'=>\$daytime));
		\$access['all_day']=pdo_count('core_access_log',array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin'],'createtime >'=>\$daytime));
		\$access['wechat_all']=pdo_count('core_access_log',array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin'],'os'=>2));
		\$access['wxapp_all']=pdo_count('core_access_log',array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin'],'os'=>1));
		\$access['mobile_all']=pdo_count('core_access_log',array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin'],'os'=>3));
		\$access['pc_all']=pdo_count('core_access_log',array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin'],'os'=>4));
		\$access['app_all']=pdo_count('core_access_log',array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin'],'os'=>5));
		\$access['all_all']=pdo_count('core_access_log',array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin']));
		//月份
		for(\$i=0;\$i<12;\$i++){
				if(\$i==0){
					\$yuestart = mktime(0,0,0,date('m'),1,date('Y'));
					\$yueend = time();
					
				}else{
					\$yuestart = mktime(0,0,0,date('m')-\$i,1,date('Y'));
					\$yueend = mktime(0,0,0,date('m')-\$i+1,1,date('Y'));
				}
				\$params=array('uniacid'=>\$_SESSION['uniacid'],'this'=>2,'plugin'=>\$_RQ['plugin']);
				\$params['createtime between']=array(\$yuestart,\$yueend);
				\$month12[\$i] = date('Y-m',strtotime('-'.\$i.' month'));
				//\$monthaccess[]=pdo_count('core_access_log',\$params);
				\$accessline[\$i]=pdo_count('core_access_log',\$params);
				//\$monthcredit2[]=pdo_getsum('core_members',\$params,'credit2');
		}
		\$accessline=array_reverse(\$accessline);
		\$month12=array_reverse(\$month12);
		\$return['htmls']=array(
				array('type'=>'data','one_num'=>2,'title'=>'应用今日/总访问数据指标','datas'=>array(
					array('title'=>'公众号数据','num'=>2,'data'=>array(\$access['wechat_day'],\$access['wechat_all'])),
					array('title'=>'小程序数据','num'=>2,'data'=>array(\$access['wxapp_day'],\$access['wxapp_all'])),
					array('title'=>'手机端数据','num'=>2,'data'=>array(\$access['mobile_day'],\$access['mobile_all'])),
					array('title'=>'PC端数据','num'=>2,'data'=>array(\$access['pc_day'],\$access['pc_all'])),
					array('title'=>'APP端数据','num'=>2,'data'=>array(\$access['app_day'],\$access['app_all'])),
					array('title'=>'总访问量','num'=>2,'data'=>array(\$access['all_day'],\$access['all_all'])),
				)),
				array('type'=>'echarts_arealine','ecid'=>'mobile','title'=>'月度流量数据','datas'=>array(
					'datas'=>array(
						array('name'=>'访问量','value'=>\$accessline),
					),
					'xdatas'=>\$month12,
				)),
		);
		\$setting=\$this->plugin_setting('basic');
		if(\$_SESSION['os']=='windows' && (empty(\$setting['title']) || empty(\$setting['footernav']))){
			\$return['htmls'][]=array('type'=>'intro','title'=>'新手引导','datas'=>array(
				array('element'=>'#left_menu_2_0','intro'=>'主人！您还没有设置页面噢！</br>只有设置好了页面，才能有好的体验噢！点这里设置噢！','position'=>''),
			));
		}
	exi(\$return);
}
TPL;
		$code=cfc('tools')->replace($search,$code);
		file_put_contents(ROOT_PLUGIN.$pluginname.'/manage/actions/index.php',$code);
		return true;
	}
}